package com.example.demo.demos.util;

import com.alibaba.fastjson.JSONArray;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class Test {

    public static void main(String[] args) {

        Map<Integer, String> map = new HashMap<>();

        map.put(3, "z");
        map.put(1, "a");
        map.put(6, "g");
//        System.out.println(map);




        map.entrySet().stream().forEachOrdered(t -> {
            Map<Integer, String> map1 = new HashMap<>();
            map1.put(t.getKey(), t.getValue());
            Map<String, String> map2 = getMap(t.getKey(), t.getValue());

        });

        map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByKey())).forEachOrdered(t -> {
            Map<String, String> map1 = getMap(t.getKey(), t.getValue());
//            System.out.println(JSONArray.toJSON(map1.toString()));
        });

        map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(t ->{
            Map<String, String> map1 = getMap(t.getKey(), t.getValue());
            System.out.println(JSONArray.toJSON(map1.toString()));
        });

    }

    public static Map<String, String> getMap(Integer a, String b) {
        Map<String, String> hashMap = new LinkedHashMap<>();
        hashMap.put("key："+a, "value：" + b);
        return hashMap;
    }
}
